//app.js
App({
  sendMsg() {
    wx.requestSubscribeMessage({
      tmplIds: ['SQ7U_NT4gGV_msdgTpPiARDFIQIv1ECFxCYFBP_apkg', 'bzyl7or1NmoyNJ_OEajl0I9WBpJ7idMLgqWjsjqS7RU', 'eDqGleQrM6Q9OL1d54CknCpSwG1_9w5z-Pn_fj6rng0'],
      success(res) {
        console.log('res1', res)
      },
      fail(err) {
        console.log('err2', err)
      }
    })
  },
  async getOpenid() {
    if (wx.getStorageSync('openid')) {
      return wx.getStorageSync('openid');
    } else {
      return (await wx.cloud.callFunction({
        name: "openId"
      })).result.openid;
    }
  },
  async AppUserAdd(userInfo={},nav) {
    let get_user = await wx.cloud.callFunction({
      name: "get_user"
    });
    userInfo.userInfoDetail = {};
    userInfo.id_num = 6230001 + get_user.result.data.length;
    userInfo.user_status = true
    userInfo.seeNum = 0
    userInfo.tiwenNum = 0
    userInfo.zan_openid = []
    userInfo._id = await this.DB.collection('user').add({
      data: userInfo
    })._id;

    wx.setStorageSync('userInfo', userInfo)
    if(nav){
      wx.navigateTo({
        url: '/pages/info/index?nav_type=login' // 这里是要跳转的路径
      })
    }
    return userInfo;
  },
  async onLaunch() {
    // 云开发环境初始化
    wx.cloud.init({
      env: 'gezi-ofhmx'
    })
    this.DB = wx.cloud.database()
    console.log('this.openid11', this.getOpenid())

    this.openid = await this.getOpenid()

    // 在其它页面这样判断鉴权信息
    if (getApp().isLoginStatus) {
      console.log('登录成功')
    }


    wx.setStorageSync('openid', this.openid)
    console.log('this.openid', this.openid)


    this.guanli_list_openid = ['odRMY0QKotP0SAqoOfDpT3VY_MtI', 'odRMY0ew6xdhoqZoKlgrdPvez-eI']
  }

})